I'm trying to add some motif stuff to my C++ program but I'm having a problem with callbacks. I have classes that implement gui components but I don't know how to pass a pointer to a member function to motif, so that motif can call the member function as a callback. Can you help? Ellaboration follows....
Background: Motif expects the programmer to pass a pointer to a function whenever you make a callback, so that when, say a button is pushed, then the specified function will be called. The function might print out "Hey, stop pushing me!" Alright fine, but I don't want motif to call just a plain function, I want it to call a certain member function (or method) of the class that is registering the callback.
The Problem: Unlike plain functions, you can't easily (or at all?) get a pointer to the member function that is complete enough to invoke the method from. Pointers to member function usually (as far as I've seen) come in two parts, a pointer to the object & an offset points to the member. Both are needed to invoke the member function.
What I've tried: I've been able to do the following: I can get a pointer to the object, and I can the offset of the member function, which lets me do something like this:
I can even pass the 'Pointer_To_Object' as client_data to the callback, letting me call a method if it is always the same, so I can do this in the motif function callback:
Pointer_To_Object->Callback();
This works well, allowing all of my classes to specifiy a single function as the callback, which in turn will call the 'Callback()' member function when invoked, but what if I don't always want to call 'Callback()'. Since one class might have more than one callback (say, one for "OK" & one for "CANCEL"), how can I get motif to call a member function as a callback?
The QUESTION:
1) How can I get a SINGLE pointer to a member function that can be invoked when it is passed to some third party?
-or-
2) Is there some clever way to get motif to call any given member function from a 'function' callback?